#include <cassert>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

const int maxQ = 1000;
const int maxC = 1000;
const int maxLen = (int)1e4;
const int maxA = 11;

int ma, qn, cn, num_q[maxQ][maxA], num_c[maxQ][maxA];
char *q[maxQ];
char *name[maxC], *answer[maxC];
char s[maxLen];

int type( char c )
{
  return ('0' <= c && c <= '9') ? c - '0' : -1;
}

int main( int argc, char *argv[] )
{
  if (argc < 2)
  {
    puts("Usage: <file_with_questions>");
    return 1;
  }

  assert(freopen(argv[1], "rt", stdin));
  while (gets(s))
    if (strlen(s) >= 3 && s[0] != '#')
      assert(qn < maxQ), q[qn++] = strdup(s);
  fclose(stdin);

  sprintf(s, "%s.ans", argv[1]);
  assert(freopen(s, "rt", stdin));
  while (gets(s))
    if (strlen(s) > 3)
    {
      char *t = strdup(s);
      assert(cn < maxC);
      answer[cn] = t, name[cn] = t + qn + 1;
      forn(i, qn)
      {
        int t = type(answer[cn][i]) + 1;
        assert(t < maxA);
        num_q[i][t]++;
        num_c[cn][t]++;
        ma = max(ma, t);
      }
      cn++;
    }

  forn(i, qn)
  {
    forn(t, ma)
      printf("%2d ", num_q[i][t + 1]);
    printf(" ");
    forn(j, cn)
      printf("%c", answer[j][i]);
    printf("  %s", q[i]);
    puts("");
  }
  puts("");
  forn(i, cn)
  {
    forn(j, ma)
      printf("%2d ", num_c[i][j + 1]);
    printf("  %s\n", name[i]);
  }

/*
  const char *f = "Деление";
  puts("");
  forn(i, cn)
  {
    int down = 0;
    forn(j, qn)
      if (strstr(q[j], f))
        down += type(answer[i][j]);
    printf("%2d : %s\n", down, name[i]);
  }
*/
  return 0;
}
